module VGA_CTRL_test(
	clk			,
	rst_n			,
	VGA_RGB		,
	VGA_HS		,
	VGA_VS		,
	VGA_BLK		,
	VGA_CLK		
);

	input							clk		;									
	input							rst_n		;					  			
	output			[23:0]	VGA_RGB	;			
	output						VGA_HS	;			
	output						VGA_VS	;			
	output						VGA_BLK	;		
   output   					VGA_CLK	;	
	
	localparam	BLACK		=	24'h000000,//黑色
					BLUE		=	24'h00000F,//蓝色
					RED 		=	24'hFF0000,//红色			
					PURPPLE	=	24'hFF00FF,//紫色
					GREEN		=	24'h00FF00,//绿色
					CYAN		=	24'h00FFFF,//青色
					YELLOW	=	24'hFFFF00,//黄色	
					WHITE		=	24'hFFFFFF;//白色		
					
	localparam	R0_C0		=	BLACK	    ,//第0行0列像素块
					R0_C1		=	BLUE	    ,//第0行1列像素块
					R1_C0 	=	RED		 ,//第1行0列像素块		
					R1_C1		=	PURPPLE	 ,//第1行1列像素块
					R2_C0		=	GREEN	 	 ,//第2行0列像素块
					R2_C1		=	CYAN		 ,//第2行1列像素块
					R3_C0		=	YELLOW	 ,//第3行0列像素块	
					R3_C1		=	WHITE		 ;//第3行1列像素块	
					
	reg [23:0] disp_data;
	wire clk25m;	
	wire [9:0] hcount;
	wire [9:0] vcount;
					
	wire C0_act = hcount >= 0   && hcount < 320;//正在扫描第0列
	wire C1_act = hcount >= 320 && hcount < 640;//正在扫描第1列
	wire R0_act = vcount >= 0   && vcount < 120;//正在扫描第0行
	wire R1_act = vcount >= 120 && vcount < 240;//正在扫描第1行
	wire R2_act = vcount >= 240 && vcount < 360;//正在扫描第2行
	wire R3_act = vcount >= 360 && vcount < 480;//正在扫描第3行
	wire R0_C0_act = R0_act & C0_act;   //第0行0列像素块被扫描中
	wire R0_C1_act = R0_act & C1_act;   //第0行1列像素块被扫描中
	wire R1_C0_act = R1_act & C0_act;	//第1行0列像素块被扫描中
	wire R1_C1_act = R1_act & C1_act;   //第1行1列像素块被扫描中
	wire R2_C0_act = R2_act & C0_act;   //第2行0列像素块被扫描中
	wire R2_C1_act = R2_act & C1_act;   //第2行1列像素块被扫描中
	wire R3_C0_act = R3_act & C0_act;   //第3行0列像素块被扫描中
	wire R3_C1_act = R3_act & C1_act;   //第3行1列像素块被扫描中

	always @(*)
	case({R3_C1_act,R3_C0_act,R2_C1_act,R2_C0_act,R1_C1_act,R1_C0_act,R0_C1_act,R0_C0_act})
		8'b0000_0001:disp_data = R0_C0;
		8'b0000_0010:disp_data = R0_C1;
		8'b0000_0100:disp_data = R1_C0;
		8'b0000_1000:disp_data = R1_C1;
		8'b0001_0000:disp_data = R2_C0;
		8'b0010_0000:disp_data = R2_C1;
		8'b0100_0000:disp_data = R3_C0;
		8'b1000_0000:disp_data = R3_C1;
		default : disp_data = R0_C0;
	endcase
	
	clk25m clk25m_inst(
		.inclk0(clk),
		.c0(clk25m)
	);
		
	VGA_CTRL	VGA_CTRL_inst(
		.clk25m		(clk25m	),
		.rst_n		(rst_n	),
		.data_in  	(disp_data ),	//待显示的数据
		.hcount		(hcount	),
		.vcount		(vcount	),
		.VGA_RGB		(VGA_RGB ),
		.VGA_HS		(VGA_HS	),
		.VGA_VS		(VGA_VS	),
		.VGA_BLK		(VGA_BLK ),
		.VGA_CLK		(VGA_CLK )		
	);
endmodule 